﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;


public partial class UserControls_PageInterface : System.Web.UI.UserControl
{
    private string _currentPageName = "";
    private int _currentPageNumber;
    private int _totalNumberOfPage;
    private int _rowPerPage;
   
    private string _parameter;
    public ArrayList _paraName;
    public System.Collections.ArrayList ParaName
    {
        get { return _paraName; }
        set { _paraName = value; }
    }
    public ArrayList _paraValue;
    public System.Collections.ArrayList ParaValue
    {
        get { return _paraValue; }
        set { _paraValue = value; }
    }
    

   
    public string currentPageName
    {
        get
        {
            return _currentPageName;
        }
        set
        {
            _currentPageName = value;
        }
    }

    public int currentPageNumber
    {
        get
        {
            return _currentPageNumber;
        }
        set
        {
            _currentPageNumber = value;
        }
    }
    public int totalNumberOfPage
    {
        get
        {
            return _totalNumberOfPage;
        }
        set
        {
            _totalNumberOfPage = value;
        }
    }
    public int rowPerPage
    {
        get { return _rowPerPage; }
        set { _rowPerPage = value; }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        //_paraName = new ArrayList();
        //_paraValue = new ArrayList();
        if (totalNumberOfPage == 0)
            totalNumberOfPage = 1;
        Label1.Text = "Trang "+(currentPageNumber+1)+"/" + totalNumberOfPage;
        if (currentPageNumber == totalNumberOfPage - 1)
        {
            btnNext.Enabled = false;
            btnLast.Enabled = false;
        }
        if (currentPageNumber == 0)
        {
            btnFirst.Enabled = false;
            btnPrev.Enabled = false;
        }
        if (currentPageNumber > 0 && currentPageNumber < totalNumberOfPage - 1)
        {
            btnNext.Enabled = true;
            btnLast.Enabled = true;
            btnFirst.Enabled = true;
            btnPrev.Enabled = true;
        }
        if(_paraName != null)
        {
            for (int i = 0; i < _paraName.Count; i++)
            {
                _parameter = "&" + _paraName[i] + "=" + _paraValue[i];


            }
        }
        
            
    }
    protected void btnFirst_Click(object sender, EventArgs e)
    {
        Response.Redirect(currentPageName + "?page=0" +  _parameter);

    }
    protected void btnPrev_Click(object sender, EventArgs e)
    {
        Response.Redirect(currentPageName + "?page=" + (currentPageNumber - 1) +  _parameter);
    }
    protected void btnNext_Click(object sender, EventArgs e)
    {
        Response.Redirect(currentPageName + "?page=" + (currentPageNumber + 1) + _parameter);
    }
    protected void btnLast_Click(object sender, EventArgs e)
    {
        Response.Redirect(currentPageName + "?page=" + (totalNumberOfPage - 1) + _parameter);
    }
    protected void btnGoTo_Click(object sender, EventArgs e)
    {
        try
        {
            int k = int.Parse(txtPageNumber.Text) - 1;
            if (k >= 0 && k < totalNumberOfPage)
                Response.Redirect(currentPageName + "?page=" + k.ToString() + _parameter);
            else
                txtPageNumber.Text = "";
        }
        catch(Exception ex)
        {
        }
    }
}
